﻿using System;
using System.Xml.Serialization;

namespace Sovacode.RubiksCube.Common.Attributes
{
    /// <summary>
    /// Class CommandInfoAttribute.
    /// </summary>
    [Serializable]
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
    public sealed class CommandInfoAttribute : System.Attribute
    {
        #region Private Fields

        /// <summary>
        /// The _command name
        /// </summary>
        private string _commandName;

        /// <summary>
        /// The _input gesture text
        /// </summary>
        private string _inputGestureText;

        /// <summary>
        /// The _method name
        /// </summary>
        private string _methodName;

        /// <summary>
        /// The _description
        /// </summary>
        private string _description;

        #endregion


        #region Constructor

        /// <summary>
        /// Prevents a default instance of the <see cref="CommandInfoAttribute"/> class from being created.
        /// </summary>
        private CommandInfoAttribute()
        {

        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CommandInfoAttribute"/> class.
        /// </summary>
        /// <param name="commandName">Name of the command.</param>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="inputGestureText">The input gesture text.</param>
        /// <param name="description">The description.</param>
        public CommandInfoAttribute(string commandName, string methodName = "", string inputGestureText = "", string description = "")
        {
            CommandName = commandName;
            InputGestureText = inputGestureText;
            MethodName = methodName;
            Description = description;
        }

        #endregion


        #region Public Properties

        /// <summary>
        /// Gets the name of the command.
        /// </summary>
        /// <value>The name of the command.</value>
        [XmlElement("Command")]
        public string CommandName
        {
            get { return _commandName; }
            set
            {
                if (string.IsNullOrWhiteSpace(_commandName))
                {
                    _commandName = value;
                }
            }
        }

        /// <summary>
        /// Gets the input gesture text.
        /// </summary>
        /// <value>The input gesture text.</value>
        [XmlElement("Gesture")]
        public string InputGestureText
        {
            get { return _inputGestureText; }
            set
            {
                if (string.IsNullOrWhiteSpace(_inputGestureText))
                {
                    _inputGestureText = value;
                }
            }
        }

        /// <summary>
        /// Gets the name of the method.
        /// </summary>
        /// <value>The name of the method.</value>
        [XmlElement("Method")]
        public string MethodName
        {
            get { return _methodName; }
            set
            {
                if (string.IsNullOrWhiteSpace(_methodName))
                {
                    _methodName = value;
                }
            }
        }

        /// <summary>
        /// Gets the description.
        /// </summary>
        /// <value>The description.</value>
        [XmlElement("Description")]
        public string Description
        {
            get { return _description; }
            set
            {
                if (string.IsNullOrWhiteSpace(_description))
                {
                    _description = value;
                }
            }
        }

        #endregion
    }
}